package Connections;

import Gear.Factory;

import java.net.Socket;

/**
 * Thread that deal with a new connection on tracker server.
 *
 * @author Rodrigo Martins Racanici
 */
public class TrackerHandler extends ConnectionHandler {

    /**
     * Handler Constructor.
     *
     * @param client Client socket.
     */
    public TrackerHandler(Socket client) {
        super(client);
    }

    /**
     * Deal with a new connection.
     */
    @Override
    public void run() {

        String[] command = Factory.getInstance().getTracker().receiveCommand(client).trim().split(";");

        for (String c : command) {
            String[] args = c.trim().split("\"{1,2}");

            //Factory.getInstance().getTracker().sendFile(client, FileSystems.getDefault().getPath(Factory.getInstance().getSettings().getGearPath().toString(), c).toFile());
            Factory.getInstance().getTracker().getCommands().get(args[0].trim()).execute(client, args);
        }
    }
}
